from typing import List


class Solution:
    def longestSubarray(self, nums: List[int]) -> int:
        l = 0
        res = 0
        has = False
        for i in range(len(nums)):
            # 如果已经遇到0，并且当前元素也是0，则移动左指针直到左指针指向的元素不是0
            while has and nums[i] == 0:
                if nums[l] == 0:
                    has = False
                l+=1
            if nums[i] ==0:
                has =True
            res = max(res,i-l)
        return res